//柱状图

var barTabLeft1=[
	{
		name: '涉政',
		data: [30,0]
	},{
		name: '淫秽色情', 
		data:[74,20]
	}
]

var barTabMiddle1=[
	{name: '涉政', data:[2,0]},
	{name: '色情', data:[0,18]}
]

var barTabRight1=[
	{name: '淫秽色情', data:[270, 34]},
	{name: '涉政', data:[30, 0]}
]

var barTabLeft2=[
	{
		name: '高教自考',
		data: [66, 0, 0]
	},{
		name: '同等学历', 
		data:[0, 51, 0]
	},{
		name: '高考', 
		data:[0,0,36]
	}
]

var barTabMiddle2=[
	{name: '高教自考', data:[105, 0, 0]},
	{name: '同等学历', data:[0, 10, 0]},
	{name: '高考', data:[0, 0, 200]}
]

var barTabRight2=[
	{name: '高教自考', data:[15, 0]},
	{name: '考研', data:[0, 51]}
]
var barTabLeft3=[
	{name: '涉政谣言', data:[18,0,0,0]},
	{name: '涉医师资格考试', data:[0,22,0,0]},
	{name: '涉会计师资格考试', data:[0,0,20,0]},
	{name: '涉政不良信息', data:[0,0,0,68]}
]

var barTabMiddle3=[
	{name: '涉政谣言', data:[70,0,0,0]},
	{name: '涉医师资格考试', data:[0,70,0,0]},
	{name: '涉会计师资格考试', data:[0,0,50,0]},
	{name: '涉政不良信息', data:[0,0,0,100]}
]

var barTabRight3=[
	{name: '涉政谣言', data:[18,0]},
	{name: '涉会计师资格考试', data:[0,20]}
]

var barTabLeft0=[
	{
		name: '社会谣言',
		data: [27,0]
	},{
		name: '涉政谣言', 
		data:[0,8]
	}
]

var barTabMiddle0=[
	{name: '社会谣言', data:[7, 0]},
	{name: '涉政谣言', data:[0, 3]}
]

var barTabRight0=[
	{name: '涉政类', data:[16, 0, 18, 10]},
	{name: '涉赌类', data:[0, 20, 0, 0]}
]


var timeData01=['2017-07', '2017-12']
var timeData02=['2017-07', '2017-12']
var timeData03=['2017-08','2017-09','2017-10','2017-11']
var timeData11=['2017-03', '2017-09']
var timeData12=['2017-03', '2017-09']
var timeData13=['2017-03','2017-09']
var timeData21=['2017-04', '2017-05', '2017-06']
var timeData22=['2017-04', '2017-05', '2017-06']
var timeData23=['2017-04','2017-12']
var timeData31=['2017-01','2017-09','2017-10','2017-11']
var timeData32=['2017-01','2017-08','2017-09','2017-10']
var timeData33=['2017-01','2017-08']

function seriesNameData(opt,serData){
//	opt.series.length =0;
	var arr1 = new Array();
	for(var i=0;i<serData.length;i++){
		var obj=new Object();
		obj.name=serData[i].name
		obj.data=serData[i].data
		obj.type='bar'
		obj.stack='same'
		obj.barWidth=40
		arr1.push(obj)
	}
	opt.series = arr1
}

function legendData(data){
	var arr=[];
	for(var i=0;i<data.length;i++){
		arr.push(data[i].name)
	}
	return arr;
}

var barOpt=function(){
	return {
//		color : ["#fce24f","#b8ff2e","#09e24b","#09e2cb","#09a7e2", "#0841b6", "#30059c", "#68059c","#9c058c","#9c0550"],
		color : ["#0ba5e1", "#00e7d8","#c9ff63","#fce24f"],
		tooltip: {
			trigger: 'axis',
			confine: true,
			axisPointer: { // 坐标轴指示器，坐标轴触发有效
				type: 'shadow' // 默认为直线，可选为：'line' | 'shadow'
			},
//			formatter: '{a1},{a2},{a3},{a0}'
//			
		},
		legend: {
			textStyle:{
				color: '#fff'
			},
			data: []
		},
		grid: {
			left: '3%',
			right: '4%',
			bottom: '3%',
			containLabel: true
		},
		xAxis: {
			type: 'category',
			splitLine:{    //grid区域分隔线
            show:true,
            lineStyle: {
                width:1,
                type:"dashed",
                color:"#48484a"
            }
        },
        axisLabel: {  //坐标轴标签
            show: true,
            textStyle: {
                color: '#0d7790'
            }
        },
        axisTick: {
            show: true,   //刻度线
            color:'#c0d4da'
        },
        axisLine:{
            show: true,   //坐标轴轴线
            lineStyle: {
                width:1,
                color:"#c0d4da"
            }
        },
			data: []
		},
		yAxis: [{
			type: 'value',
			 splitLine:{    //grid区域分隔线
            show:true,
            lineStyle: {
                width:1,
                type:"dashed",
                color:"#1a1a1b"
            }
        },
        axisTick: {
        	color:'#c0d4da',
            show: true   //刻度线
        },
        axisLine: {
            show: true ,  //坐标轴轴线
            lineStyle: {
                width:1,
                color:"#c0d4da"
            }
        },
        axisLabel: {  //坐标轴标签
            show: true,
//          formatter: function(data) {
//          	if(unit == null) {
//          		unit = ''
//          	}
//          	return  data + unit;
//	          }
        }
		}],
		series: [
			{
				name: '',
				type: 'bar',
				stack: '',
				barWidth: '50%',
				data: []
			}
		]
	}
}

//var dataBarLeg=function(data){
//	var dataLe=[];
//	for(var i=0;i<data.length;i++){
//		dataLe.push(data[i].name)
//	}
//	return dataLe
//}

var bar1Chart = echarts.init(document.getElementById('ecBar1st'));
var bar2Chart = echarts.init(document.getElementById('ecBar2nd'));
var bar3Chart = echarts.init(document.getElementById('ecBar3th'));


//function toolTipOpt(objData){
//	var ecOpt=barOpt();
//	var obj=''
//	ecOpt.tooltip.formatter=function(param){
//		console.log(param)
//	}
//}

function optionFn(ecObj,timeData,objData,value){
	var barLeft1st=barOpt();
	if(value == '教育'){
		barLeft1st.yAxis[0].name = '单位/万';
	}
	seriesNameData(barLeft1st,objData)
	barLeft1st.xAxis.data=timeData
	barLeft1st.legend.data=legendData(objData)
	/*barLeft1st.tooltip.formatter=function(param){
		var obj=''
		for(var i=0;i<objData.length;i++){
			if(param[i]){
				obj+=param[i].marker+param[i].seriesName +':'+ param[i].value+'<br>'
			}
		}
		return obj
	}*/
	ecObj.setOption(barLeft1st,true);
}
optionFn(bar1Chart,timeData01,barTabLeft0)
optionFn(bar2Chart,timeData02,barTabMiddle0)
optionFn(bar3Chart,timeData03,barTabRight0)


var n=0;
$(".ec_tab li").click(function(){
	n=$(this).index();
	$(this).addClass("active").siblings().removeClass("active")
	if(n==0){//部网安局
		optionFn(bar1Chart,timeData01,barTabLeft0)
		optionFn(bar2Chart,timeData02,barTabMiddle0)
		optionFn(bar3Chart,timeData03,barTabRight0)
	}else if(n==1){//打黄打非办
		optionFn(bar1Chart,timeData11,barTabLeft1)
		optionFn(bar2Chart,timeData12,barTabMiddle1)
		optionFn(bar3Chart,timeData13,barTabRight1)
	}else if(n==2){//教育部
		optionFn(bar1Chart,timeData21,barTabLeft2)
		optionFn(bar2Chart,timeData22,barTabMiddle2,'教育')
		optionFn(bar3Chart,timeData23,barTabRight2)
	}else{//其他
		optionFn(bar1Chart,timeData31,barTabLeft3)
		optionFn(bar2Chart,timeData32,barTabMiddle3)
		optionFn(bar3Chart,timeData33,barTabRight3)
	}
})

window.addEventListener("resize", function () {
    bar1Chart.resize();
    bar2Chart.resize();
    bar3Chart.resize();
});